<template>
    <view class='page'>
        <view v-show="scrollTop>20">
            <u-navbar class="gradient-bg" title="蔚蓝至善商家端" navbarType="4" fontColor="#ffffff" gradient="linear-gradient(to bottom right, #2e996f, #3f99ab)"></u-navbar>
        </view>       
        <view class="my-top">
            <view class="txt">
                <view class="txtl">
                    <view class="item">
                        <text class="num">￥{{data && data.income?data.income.today.toFixed(2):0.00}}</text>
                        <text class="data">今日收入（元）</text>
                    </view>
                    <view class="item">
                        <text class="num">￥{{data && data.income?data.income.thisweek.toFixed(2):0.00}}</text>
                        <text class="data">本周收入（元）</text>
                    </view>
                </view>
                <view class="line"></view>
                <view class="txtl">
                    <view class="item">
                        <text class="num">￥{{data && data.income?data.income.yesterday.toFixed(2):0.00}}</text>
                        <text class="data">昨日收入（元）</text>
                    </view>
                    <view class="item">
                        <text class="num">￥{{data && data.income?data.income.thismonth.toFixed(2):0.00}}</text>
                        <text class="data">本月收入（元）</text>
                    </view>
                </view>
            </view>
            <!-- <view class="btn box">
                营收详情
            </view> -->
        </view>
        <view class="box1">
            <view class="box">
                <view class="l">
                    <picker class="text" mode="date" :fields="pickType" :value="time" start="2023-05-16" @change="DateChange">
                        <view class="li">
                            <text class="p">{{time}}</text>
                            <image src="../../static/index/calendar.png" mode="widthFix"></image>
                        </view>
                    </picker>
                </view>
                <view class="r">
                    <view class="item" :class="{'active' : curIndex==index+1}" v-for="item,index in dataList" :key="index" @click="selectTab(index+1)">
                        {{item.name}}
                    </view>
                </view>
            </view>
        </view>
        <view class="box2 box">
            <view class="item">
                <image src="../../static/index/note.png" mode="widthFix"></image>
                <view class="txt">
                    <text>{{data && data.orders?data.orders.receiv:0}}</text>
                    <text>已接单</text>
                </view>
            </view>
            <view class="item">
                <image src="../../static/index/aircraft.png" mode="widthFix"></image>
                <view class="txt">
                    <text>{{data && data.orders?data.orders.place:0}}</text>
                    <text>未接单</text>
                </view>
            </view>
            <view class="item">
                <image src="../../static/index/service.png" mode="widthFix"></image>
                <view class="txt">
                    <text>{{data && data.orders?data.orders.cancel:0}}</text>
                    <text>已取消</text>
                </view>
            </view>
            <view class="item">
                <image src="../../static/index/check.png" mode="widthFix"></image>
                <view class="txt">
                    <text>{{data && data.orders?data.orders.complete:0}}</text>
                    <text>已完成</text>
                </view>
            </view>
        </view>
        <view class="box box3">
            <view class="tit">
                <view class="line"></view>
                <text class="p">今日服务进度</text>
            </view>
            <view class="charts-box">
                <!-- 演示动态改变eopts -->
                <qiun-data-charts v-if="isLogin" type="ring" :opts="{legend:{position:'bottom'}}" :eopts="ringOpts" :chartData="chartsDataPie2"
                    :echartsH5="true" :echartsApp="true" />
                <qiun-data-charts v-else type="ring" :opts="{legend:{position:'bottom'}}" :eopts="ringOpts" :chartData="chartsDataPie0" :echartsH5="true"
                    :echartsApp="true" />
            </view>
        </view>
        <!-- <view class="box search">
            <uni-search-bar cancelButton="none" @confirm="search" :focus="false" v-model="queryParams.key_name" @blur="blur" @input="input" @cancel="cancel"
                @clear="clear">
            </uni-search-bar>
        </view> -->
        <public-module></public-module>

        <TabBar></TabBar>
    </view>
</template>
<script>
import { home } from "@/api/index.js"
export default {
    components: {},
    data() {
        return {
            single: "",
            dataList: [
                { id: 1, name: "日" },
                { id: 2, name: "月" },
                { id: 3, name: "年" },
            ],
            curIndex: 1,
            pickType: '',
            time: "",
            ringOpts: {},
            chartsDataPie0: {

            },
            chartsDataPie2: {
            },
            queryParams: {
                order_type: 1,
                format_date: "",
            },
            isLogin: uni.getStorageSync('token') ? true : false,
            data: {},
            scrollTop: 0,
            // bgColor: {
            //     // 渐变色
            //     backgroundImage: 'linear-gradient(to bottom right, #2e996f, #3f99ab)'
            // },
        };
    },
    onLoad(options) {

    },
    onPageScroll(e) {
        console.log(e, "eeeee")
        this.scrollTop = e.scrollTop;
    },
    onShow() {
        setTimeout(() => {
            this.chartsDataPie0 = {
                "series": [{
                    "data": [
                        {
                            "name": "已接单",
                            "value": 0
                        }, {
                            "name": "已完成",
                            "value": 0
                        }, {
                            "name": "已取消",
                            "value": 0
                        }, {
                            "name": "未接单",
                            "value": 0
                        },
                    ]
                }]
            }
        }, 1000);
        this.getDate()
        if (this.isLogin) {
            this.getList()
        }
    },
    onReady() {
        // setTimeout(() => {
        //     //测试动态绑定的eopts
        //     this.ringOpts = {
        //         color: ['#FF00FF', '#AAFF11'],
        //         legend: { show: false }
        //     }
        // }, 5000);
    },
    methods: {
        getList() {
            this.queryParams.format_date = this.time
            home(this.queryParams).then((res) => {
                this.data = res.data
                if (this.data && this.data.orders) {
                    setTimeout(() => {
                        this.chartsDataPie2 = {
                            "series": [{
                                "data": [
                                    {
                                        "name": "已接单",
                                        "value": this.data.orders.receiv
                                    }, {
                                        "name": "已完成",
                                        "value": this.data.orders.complete
                                    }, {
                                        "name": "已取消",
                                        "value": this.data.orders.cancel
                                    }, {
                                        "name": "未接单",
                                        "value": this.data.orders.place
                                    },
                                ]
                            }]
                        }
                    }, 1000);
                }

            })
        },
        getDate() {
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1;
            let dd = new Date().getDate();
            if (this.curIndex == 3) {
                this.time = yy
            } else if (this.curIndex == 2) {
                this.time = yy + '-' + (mm < 10 ? '0' + mm : mm);
            } else if (this.curIndex == 1) {
                this.time = yy + '-' + (mm < 10 ? '0' + mm : mm) + '-' + (dd < 10 ? '0' + dd : dd);
            }
        },
        selectTab(index) {
            if (index == 3) {
                this.pickType = 'year'
            } else if (index == 2) {
                this.pickType = 'month'
            } else if (index == 1) {
                this.pickType = ''
            }
            this.curIndex = index
            this.getDate()
            this.getList()
        },
        DateChange(e) {
            this.time = e.detail.value
        },
        search(res) {
            // uni.showToast({
            //     title: '搜索：' + res.value,
            //     icon: 'none'
            // })
        },
        input(res) {
            // console.log('----input:', res)
        },
        clear(res) {

        },
        blur(res) {

        },
        // focus(e) {
        //     uni.showToast({
        //         title: 'focus事件，输出值为：' + e.value,
        //         icon: 'none'
        //     })
        // },
        cancel(res) {
            uni.showToast({
                title: '点击取消，输入值为：' + res.value,
                icon: 'none'
            })
        },
    },
};
</script>
<style scoped lang='scss'>
.page {
  position: absolute;
  width: 100%;
  // height: 100%;
  padding-bottom: 150rpx;
  background-color: #f6f6f6;
}
.my-top {
  //   position: relative;
  width: 100%;
  padding-bottom: 20rpx;
  background-image: linear-gradient(0deg, #4199b2 0%, #2d996b 100%),
    linear-gradient(#4ea5ff, #4ea5ff);
  background-blend-mode: normal, normal;
  overflow: hidden;
  .head {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100rpx;
    /* #ifdef APP-PLUS || H5 */
    height: calc(100rpx + var(--status-bar-height));
    padding-top: var(--status-bar-height);
    /* #endif */
    /* #ifdef MP */
    height: calc(100rpx + var(--status-bar-height));
    /* #endif */
    // background-color: rgba(255, 255, 255, 0);
    background: linear-gradient(to bottom right, #2e996f, #3f99ab);

    // transition: all 1s;

    .title {
      display: flex;
      align-items: center;

      text {
        // color: #212121;
        color: #ffffff;
        font-size: 28rpx;
      }
    }
  }
  .txt {
    width: 80%;
    margin: 0 auto;
    padding-top: calc(90rpx + var(--status-bar-height));
    display: flex;
    justify-content: space-between;
    .line {
      width: 1rpx;
      height: 102rpx;
      background-color: #ffffff;
    }
    .txtl {
      //   height: 274rpx;
      overflow: hidden;
      .item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-bottom: 45rpx;
        .num {
          font-size: 45rpx;
          color: #ffffff;
          padding-bottom: 10rpx;
        }
        .data {
          font-size: 24rpx;
          color: #ffffff;
          opacity: 0.64;
        }
      }
    }
  }
  .btn {
    width: 690rpx;
    height: 86rpx;
    // background-color: #ff6a00;
    border-radius: 20rpx;
    border: solid 1px #ffffff;
    line-height: 86rpx;
    text-align: center;
    color: #ffffff;
    // margin-top: 40rpx;
  }
}
.box1 {
  .box {
    display: flex;
    justify-content: space-between;
    padding: 30rpx 0 20rpx;
    .l {
      picker {
        display: block;
        width: 330rpx;
        height: 72rpx;
        overflow: hidden;
        background-color: #ffffff;
        border: solid 2rpx #36998c;

        .li {
          height: 72rpx;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 10rpx;
          .p {
            font-size: 24rpx;
            color: #7b7b7b;
          }
          image {
            width: 41rpx;
          }
        }
      }
      /deep/.uni-date__x-input {
        height: 72rpx;
      }
    }
    .r {
      width: 330rpx;
      height: 72rpx;
      overflow: hidden;
      background-color: #ffffff;
      border: solid 2rpx #36998c;
      display: flex;
      .item {
        width: 110rpx;
        line-height: 72rpx;
        text-align: center;
        font-size: 24rpx;
        color: #7b7b7b;
        &.active {
          background-color: #3e99a8;
          color: #ffffff;
        }
      }
      .item:nth-child(2) {
        border-left: solid 2rpx #36998c;
        border-right: solid 2rpx #36998c;
      }
    }
  }
}
.box2 {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .item {
    width: 337rpx;
    height: 203rpx;
    background-color: #ffffff;
    margin-top: 20rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    image {
      width: 70rpx;
    }
    .txt {
      padding-left: 44rpx;
      text {
        display: block;
        font-size: 28rpx;
        color: #4c4c4c;
        line-height: 44rpx;
      }
    }
  }
}
.box3 {
  padding: 30rpx 0;
  background-color: #fff;
  margin-top: 20rpx;
  .tit {
    width: 90%;
    margin: 0 auto;
    border-bottom: 2rpx solid #eeeeee;
    padding-bottom: 18rpx;
    display: flex;
    align-items: center;
    .line {
      width: 8rpx;
      height: 32rpx;
      background-image: linear-gradient(0deg, #2d9c69 0%, #4299ba 100%),
        linear-gradient(#3e99a8, #3e99a8);
      background-blend-mode: normal, normal;
      box-shadow: 0px 0px 27rpx 0px rgba(49, 155, 121, 0.25);
      border-radius: 4rpx;
    }
    .p {
      padding-left: 16rpx;
      font-size: 28rpx;
      color: #4c4c4c;
    }
  }
  .charts-box {
    height: 520rpx;
  }
}
.search {
  margin-top: 20rpx;
  /deep/.uni-searchbar__box {
    background-color: #fff !important;
  }
  /deep/.uni-searchbar {
    padding: 0;
    width: 690rpx;
    margin: 0 auto;
  }
}
.gradient-bg {
  background: linear-gradient(to bottom right, #2e996f, #3f99ab)!important;
}
</style>